﻿Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class LandschaftstexturSee
    Inherits ObjektLandschaftsTextur
    Dim TexturLandschaft As Texture
    Dim FlussX, FlussY As Single
    Dim FliessgeschwX, FliessgeschwY As Single
    Dim FrameVerzoegerer As Integer
    ''' <summary>
    ''' 0=+N   1=+N+O   2=+N+S   3=+N+O+S   4=+N+O+S+W
    ''' </summary>
    ''' <remarks></remarks>
    Dim UebergangsMeshs(4) As Objekt3D

    Public Sub New()
        ID = "SEE"
        Landschaftsname = "See"
        Deckung = 0
        Tarnung = False
        Frame = True
        KP = -1
        Normal = 0
        Ausrichtungslandschaften = New String() {"OEDLAND", "EBENE", "TEMPWERFT", "TEMPFLUGHAFEN", "PLASMA", "FEUER", "METEOR", "OEDLAND", "RUINE", "SUMPF", "WALD", "BERG", "STRASSE", "WUESTE", "PIPELINE", "EBENE+SCHROTT", "HQ", "STADT", "BASIS", "WERFT", "FLUGHAFEN", "TURM", "MINIGESCHUETZ+N", "MINIGESCHUETZ+O", "MINIGESCHUETZ+S", "MINIGESCHUETZ+W", "FABRIK", "SCHWARZE GESCHUETZ+N", "SCHWARZE GESCHUETZ+O", "SCHWARZE GESCHUETZ+S", "SCHWARZE GESCHUETZ+W", "SCHWEISSNAHT", "KRISTALL", "MONOLITH", "MAUER", "PIPE", "PIPESCHWEISS", "KAPUTTEPIPESCHWEISS", "KAPUTTESCHWEISSNAHT", "KAKTEEN", "FELSEN", "AUSGETROCKNETESFLUSSBETT", "PFAD", "AUSGETROCKNETESFLUSSBETT", "FELSEN", "GIPFEL", "KAKTEEN", "KAPUTTEPIPESCHWEISS", "KIEFERN", "PIPE", "PIPELINE", "PIPESCHWEISS", "PLINE", "PLINEKAPUTT", "PLINESCHWEISS", "SCHNEE", "SCHWEISSNAHT", "STRASSENFROST", "WUESTE", "LASER", "VULKAN", "FESTUNG", "OMEGARAKETE", "MINE", "WUESTE+SCHROTT", "SCHNEE+SCHROTT", "RAKETENSILO+RAKETE", "RAKETENSILO", "PIPESTATION", "SCHOCKLASER+N", "SCHOCKLASER+O", "SCHOCKLASER+S", "SCHOCKLASER+W"}
        UebergaengeLaden("Kueste")

        FliessgeschwX = 0.001
        FliessgeschwY = -0.002
        If DataSettings.draw3D Then
            Ini3D()
        End If
        TexturenLaden(New String() {"See", "See+S", "See+O", "See+N", "See+O+W", "See+N+O", "See+O+S", "See+S+W", "See+W", "See+N+W", "See+N+S", "See+O+S+W", "See+N+O+S", "See+N+O+W", "See+N+S+W", "See+N+O+S+W"})
    End Sub

    Public Overrides Function DrawSpecialStyle(ByVal BildID As Integer, ByVal Fog As Nebelarten, ByVal Alpha As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal TerrainUntergrundID As Integer, ByVal TerrainUntergrundBildID As Integer, ByVal TerrainUntergrundID2 As Integer, ByVal TerrainUntergrundBildID2 As Integer, Optional ByVal FixedLocation As Boolean = False, Optional ByVal Top As Boolean = False) As Boolean
        If BildID > 0 Then
            Select Case DataSettings.TerrainStyle
                Case TerrainStyle.AdvanceWarsDC, TerrainStyle.CommanderWars2
                    Return DrawTerrainUndUntergrund(Alpha, Fog, BildID, X, Y, 0, 0, TerrainUntergrundID, TerrainUntergrundBildID, TerrainUntergrundID2, TerrainUntergrundBildID2, FixedLocation, Top)
                Case Else
                    Return False
            End Select
        End If
    End Function

    Public Overrides Sub Malen3D(ByVal p_MatCube As Microsoft.DirectX.Matrix, ByVal Landschaft As ObjektLandschaft)
        Grafikengine.Grafikkarte.SetTexture(0, TexturLandschaft)
        Dim standardMatrix As Matrix = Grafikengine.Grafikkarte.Transform.World
        Grafikengine.Grafikkarte.Transform.World = p_MatCube


        'Berechnen:
        Dim Farbe As Color = ObjektmarkiertesFeld.getFeldFarbe(Landschaft.KooX, Landschaft.KooY)

        Dim cube(3) As CustomVertex.PositionNormalTextured
        cube(0) = New CustomVertex.PositionNormalTextured(0, Meereshoehe, 0, 0, 1, 0, 0 + FlussX, 1 + FlussY)
        cube(1) = New CustomVertex.PositionNormalTextured(0, Meereshoehe, 1, 0, 1, 0, 0 + FlussX, 0 + FlussY)
        cube(2) = New CustomVertex.PositionNormalTextured(1, Meereshoehe, 0, 0, 1, 0, 1 + FlussX, 1 + FlussY)
        cube(3) = New CustomVertex.PositionNormalTextured(1, Meereshoehe, 1, 0, 1, 0, 1 + FlussX, 0 + FlussY)


        'Anzeigen:
        Dim M As New Material
        M.Diffuse = Farbe
        Grafikengine.Grafikkarte.Material = M
        Grafikengine.Grafikkarte.VertexFormat = CustomVertex.PositionNormalTextured.Format

        Grafikengine.Grafikkarte.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, cube)


        If Landschaft IsNot Nothing Then
            'Evtl. ja noch raender malen, damit das ganze beim Uebergang zum Festland nicht so abgehackt aussieht:
            Dim ind As Integer = 0
            Dim Rot As Single = 0
            Dim Ausr As String = getAusrichtungVereinfacht(Landschaft.KooX, Landschaft.KooY, Objektverwalter.Spielfeld, Rot).ToUpper
            If Not Ausr = "" Then
                Select Case Ausr
                    Case "+N"
                        ind = 0
                    Case "+N+O"
                        ind = 1
                    Case "+N+S"
                        ind = 2
                    Case "+N+O+S"
                        ind = 3
                    Case "+N+O+S+W"
                        ind = 4
                End Select
                Dim Mat As Matrix = Matrix.RotationY(Rot)
                Mat.M41 = p_MatCube.M41 + 0.5
                Mat.M42 = p_MatCube.M42
                Mat.M43 = p_MatCube.M43 + 0.5
                UebergangsMeshs(ind).Malen(Mat)
            End If
        End If

        'Wieder den Ursprungsstatus wiederherstellen..
        Grafikengine.Grafikkarte.Transform.World = standardMatrix
    End Sub

    Public Overrides Sub Ini3D()
        UebergangsMeshs(0) = New Objekt3D()
        UebergangsMeshs(1) = New Objekt3D()
        UebergangsMeshs(2) = New Objekt3D()
        UebergangsMeshs(3) = New Objekt3D()
        UebergangsMeshs(4) = New Objekt3D()
        UebergangsMeshs(0).MeshBildLaden(DataSettings.Resourcenpfad + "Terrain\Meshes\See+N.x")
        UebergangsMeshs(1).MeshBildLaden(DataSettings.Resourcenpfad + "Terrain\Meshes\See+N+O.x")
        UebergangsMeshs(2).MeshBildLaden(DataSettings.Resourcenpfad + "Terrain\Meshes\See+N+S.x")
        UebergangsMeshs(3).MeshBildLaden(DataSettings.Resourcenpfad + "Terrain\Meshes\See+N+O+S.x")
        UebergangsMeshs(4).MeshBildLaden(DataSettings.Resourcenpfad + "Terrain\Meshes\See+N+O+S+W.x")
        TexturLandschaft = Grafikengine.LoadTexture(DataSettings.Resourcenpfad + "Terrain\Overworld\3D\" + DataSettings.TexturQuali + "\Wasser.png")
    End Sub
    Public Overrides Sub Tick()
        FrameVerzoegerer += 1
        If FrameVerzoegerer > 1 Then
            FlussX += FliessgeschwX
            FlussY += FliessgeschwY
            If FlussX > 1 Then FlussX -= 1
            If FlussY > 1 Then FlussY -= 1
            If FlussX < -1 Then FlussX += 1
            If FlussY < -1 Then FlussY += 1

            FrameVerzoegerer = 0
        End If
    End Sub

    Public Overrides Function GetTerrainUntergrund() As String()
        Return New String() {"SEE"}
    End Function
End Class
